 /* 
 * File:   cChaseCamera.cpp
 * Author: josep
 * 
 * Created on 12 / desembre / 2010, 23:47
 */

#include "cChaseCamera.h"

cChaseCamera::cChaseCamera():cScrollCamera() {
}

cChaseCamera::cChaseCamera(const cChaseCamera& orig):cScrollCamera(orig) {
}

cChaseCamera::~cChaseCamera() {
}

void cChaseCamera::Show(){
	float k=0.01;
	float dist;
	dist = PhysicalObject->GetPosX()-(GetPosX()+(GetWidth()/2));
	SetDirectionX(1);
	SetSpeedX(k*dist);
	dist =PhysicalObject->GetPosY()-(GetPosY()+(GetHeight()/2));
	SetDirectionY(1);
	SetSpeedY(k*dist);
	cScrollCamera::Show(1);
    
	/*
    float dif=0;
    int difLastPos = PhysicalObject->GetPosX()-LastPos[X];
    if(difLastPos>0){
        SetDirectionX(1);
    }else if(difLastPos<0){
        SetDirectionX(-1);
    }else{
        SetDirectionX(0);
    }
    if(GetDirectionX()>0){
        dif=abs(PhysicalObject->GetPosX()-GetPosX());
    }else if(GetDirectionX()<0){
        dif=abs(GetPosX()+GetWidth()-PhysicalObject->GetPosX());
    }

    //cout << "dif: " << dif << "incX: " << inc[X] << "\n";
    //cout << "speedX: " << dif/inc[X] << "\n";

    dif-=100;
    
    SetSpeedX(dif/inc[X]);

    difLastPos = PhysicalObject->GetPosY()-LastPos[Y];
    if(difLastPos>0){
        SetDirectionY(1);
    }else if(difLastPos<0){
        SetDirectionY(-1);
    }else{
        SetDirectionY(0);
    }
    if(GetDirectionY()>0){
        dif=abs(PhysicalObject->GetPosY()-GetPosY());
    }else if(GetDirectionY()<0){
        dif=abs(GetPosY()+GetHeight()-PhysicalObject->GetPosY());
    }
    
    dif-=100;
    
    SetSpeedY(dif/inc[Y]);

    PosX+=GetDirectionX()*GetSpeedX();
    PosY+=GetDirectionY()*GetSpeedY();
    
	//glTranslatef(-GetPosX(),-GetPosY(), 0);
	*/
    
}

void cChaseCamera::Init(cPhysicalVisibleObject* objToChase, int Width, int Height, float SpeedX,
                                                float SpeedY, int PosX, int PosY){
	cScrollCamera::Init(objToChase, Width, Height, SpeedX, SpeedY, PosX, PosY);
    cChaseCamera::Init();
}


/*PRIVATE*/
void cChaseCamera::Init(){
    inc[X] = this->GetWidth()/20;
    inc[Y] = this->GetHeight()/20;
	LastPos[X]=PhysicalObject->GetPosX();
	LastPos[Y]=PhysicalObject->GetPosY();
}

